<template>
  <div class="login" clearfix>
    <div class="login-wrap">
      <el-row type="flex" justify="center">
        <el-form ref="loginForm" :model="user" :rules="rules" status-icon label-width="80px">
          <h3>登录</h3>
          <hr>
          <el-form-item prop="adminUsername" label="用户名">
            <el-input v-model="user.adminUsername" placeholder="请输入用户名" prefix-icon></el-input>
          </el-form-item>
          <el-form-item id="adminPassword" prop="adminPassword" label="密码">
            <el-input v-model="user.adminPassword" show-password placeholder="请输入密码"></el-input>
          </el-form-item>
          <br>
          <el-form-item>
            <el-button type="primary" icon="el-icon-upload" @click="doLogin()">登 录</el-button>
          </el-form-item>
        </el-form>
      </el-row>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "login",
  data() {
    return {
      user: {
        adminUsername: "",
        adminPassword: ""
      },
      rules:{

      }
    };
  },
  created() {},
  methods: {
    doLogin() {
      if (!this.user.adminUsername) {
        this.$message.error("请输入用户名！");
        return;
      } else if (!this.user.adminPassword) {
        this.$message.error("请输入密码！");
        return;
      } else {
        //校验用户名和密码是否正确;
        // this.$router.push({ path: "/personal" });
        this.$axios.post("http://localhost:8080/manage/login/",this.user)
            .then(response => {
              if (response.data.code == 10001) {
                this.$message.error("用户名或者密码错误，请重新登录")
              } else {
                window.localStorage.setItem("manageToken",response.data.manageToken);
                window.localStorage.setItem("admin",JSON.stringify(response.data.admin));
                this.$message.success("登陆成功!");
                this.$router.push({ path: "/manage/home" });
              }
            });
      }
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.login {
  width: 100%;
  height: 740px;
  background: url("../../assets/manage/images/sucai1.jpg") no-repeat;
  background-size: cover;
  overflow: hidden;
}
.login-wrap {
  background-color: rgba(255, 255, 255, 0.5);
  background-size: cover;

  width: 450px;
  height: 350px;
  margin: 215px auto;
  overflow: hidden;
  padding-top: 10px;
  line-height: 40px;
}
#adminPassword {
  margin-bottom: 5px;
}
h3 {
  color: #0babeab8;
  font-size: 24px;
}
hr {
  background-color: #444;
  margin: 20px auto;
}
a {
  text-decoration: none;
  color: #aaa;
  font-size: 15px;
}
a:hover {
  color: coral;
}
.el-button {
  width: 80%;
  margin-left: -50px;
}
</style>
